package itheima.springbootwebdemo.web;

import itheima.springbootwebdemo.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

@RestController
public class RequestController {
    /*  @RequestMapping("/simpleParam")
    public String simpleParam(HttpServletRequest request){
         String name = request.getParameter("name");
         String ages = request.getParameter("age");
         int age = Integer.parseInt(ages);
         System.out.println(name+"==="+age);

         return "OK";
     }*/
   /*
   @RequestMapping("/simpleParam")
   public String simpleParam(String name, int age){
        System.out.println(name+"==="+age);

        return "OK";

    }*/
  /*  @RequestMapping("/simpleParam")
    public String simpleParam(@RequestParam(name = "username",required = false) String name, int age){
        System.out.println(name+"==="+age);

        return "OK";

    }*/
    //简单实体参数
 /*   @PostMapping("/pojoParam")
    public String pojoParam(User user){
        System.out.println(user.getName()+"==="+user.getAge());
        return "OK";
    }*/
    //复杂实体参数
   /* @PostMapping("/complexPojo")
    public String complexPojo(User user){
        System.out.println(user.getName()+"==="+user.getAge()+"==="+user.getAddress().getProvince()+"==="+user.getAddress().getCity());
        return "OK";
    }*/
    //数组参数
 /*   @RequestMapping("/arrayParam")
    public String arrayParam(String[] hoppy){
        System.out.println(hoppy);
        return "OK";
    }*/
    //列表参数-集合参数
   /* @RequestMapping("/listParam")
    public String listParam(@RequestParam List<String> list){
        System.out.println(list);
        return "OK";
    }*/
    //日期参数
    /*@RequestMapping("/dataParam")
    public String dataParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime dataStr){
        System.out.println(dataStr);
        return "OK";
    }*/
    //JSON参数
   /* @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user){
        System.out.println(user);
        return "OK";
    }*/
    @RequestMapping("/pathParam/{userId}/{name}")
    public String pathParam(@PathVariable("userId") Integer id, @PathVariable String name) {
        System.out.println(id + ":" + name);
        return "OK";
    }
}



